<template>
  <div>
    <h2>Axios() 发送请求</h2>
    <button @click="axiosGetRoleist">请求数据</button>
    <!-- <p>{{ resinfo }}</p> -->
    <button @click="axiosPostrolelist">添加数据</button>
    <button @click="axiosPutrolelist">修改数据</button>
    <button @click="axiosDELETErolelist">删除数据</button>
    <button @click="axiosPATCHrolelist">批量修改数据</button>
    <div>
      <button @click="axiosGet">请求数据</button>
      <button @click="axiosuserolelist">响应拦截器</button>
      <!-- <button @click="axiosPATCH">请求数据</button> -->
    </div>
  </div>
</template>

<script setup lang="ts">
// import { ref } from 'vue'
import {
  axiosGetRoleist,
  axiosPostrolelist,
  axiosPutrolelist,
  axiosDELETErolelist,
  axiosPATCHrolelist,
  axiosGet,
  axiosuserolelist,
  apiRequest
} from '../service/study1/demo2'

// import axios from 'axios'
// let i = 361
// setInterval(() => {
//   i++
//   arr(i)
// }, 500)
// const arr = async (index: number) => {
//   await axios
//     .delete(`http://goapi.sanjitian.cn/api/roles/${index}`) // 假设这是清空数据库的接口
//     .then((response) => {
//       console.log('数据库数据清空成功:', response.data)
//     })
//     .catch((error) => {
//       console.error('清空数据库失败:', error)
//     })
// }

apiRequest('get', '/roles/page', null, { pageNum: 1, pageSize: 10 })
// .then((data) => console.log(data))
// .catch((error) => console.error(error))

apiRequest(
  'post',
  '/roles',
  {
    id: 789,
    name: '789',
    code: '89',
    sort: 88,
    status: 0,
    dataScope: 72
  },
  null
)
  .then((data) => console.log(data))
  .catch((error) => console.error(error))

apiRequest('put', '/roles/789', { name: '你笑什么！' }, null)
  .then((data) => console.log(data))
  .catch((error) => console.error(error))

apiRequest('delete', '/roles/51', null, null)
  .then((data) => console.log(data))
  .catch((error) => console.error(error))

apiRequest(
  'patch',
  `/roles/${1}/status`,
  {
    name: '53',
    code: '677',
    sort: 88,
    status: 0
  },
  { status: 0 }
)
  .then((data) => console.log(data))
  .catch((error) => console.error(error))
</script>
